#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

int main(int argc, char* argv[])
{
    FILE *pfile = fopen("test.txt", "rb+");
    if (NULL == pfile)
    {
        printf("fopen failed. errno=%d, errmsg=%s", errno, strerror(errno));
        return 0;
    }
    int iLen = 1025;

    char *sBuff = new char[iLen];
    memset(sBuff, 0, iLen);
    int readCnt = 0;
    if ((readCnt=fread(sBuff, iLen,1, pfile)) == -1)
    {
        printf("fread failed. errno=%d, errmsg=%s", errno, strerror(errno));
    }
    printf("%s\n", sBuff);
    sprintf(sBuff, "\nhello%cworld 12334567890\n", 0x1f);
    fseek(pfile, 0, 0);
    iLen = fwrite(sBuff, 1, strlen(sBuff), pfile);
    if (iLen == -1)
    {
        printf("fwrite failed. errno=%d, errmsg=%s", errno, strerror(errno));
    }
    fclose(pfile);
    pfile = NULL;
    delete []sBuff;
    return 0;
}